package com.zhg.javakc.modules.relation.controller;

import com.zhg.javakc.base.page.Page;
import com.zhg.javakc.base.util.CommonUtil;
import com.zhg.javakc.modules.materials.entity.MaterialsEntity;
import com.zhg.javakc.modules.relation.entity.RelationEntity;
import com.zhg.javakc.modules.relation.service.RelationService;
import com.zhg.javakc.modules.supplier.entity.SupplierEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/relation")
public class RelationController {

    @Autowired
    private RelationService relationService;

    @RequestMapping("/query")
    public String queryRelation(RelationEntity relationEntity , ModelMap modelMap, HttpServletRequest request, HttpServletResponse response){
          Page<RelationEntity> page=relationService.queryRelation(relationEntity,new Page<RelationEntity>(request,response));
          modelMap.put("page",page);
          return  "relation/list";
    }
    //新增
    @RequestMapping("create")
    public String view(RelationEntity relationEntity){
        relationEntity.setRelationId(CommonUtil.uuid());
        relationService.save(relationEntity);
        return "redirect:query.do";
    }

    @ResponseBody
    @RequestMapping("/queryGroup")
    public List<Map<String,Object>> queryGroup(String groupPid){
         List<Map<String,Object>> list=relationService.queryGroup(groupPid);
        return list;
    }

    @ResponseBody
    @RequestMapping("queryGam")
    public List<Map<String,Object>> queryGam(){
        List<Map<String,Object>> list=relationService.queryGam();
        return list;

    }

}
